<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>酷妈妈商城</title>
<script type="text/javascript">
function change(id){
	var num = document.getElementById("shop"+id).value;
	if(isNaN(num)){
		alert("非数字");
		return;
	}
	location.href="<%=basePath %>updateCart?id="+id+"&"+"num="+num;
}
</script>
<style type="text/css">
table {
	border: 1px solid #eee;
}

.line {
	border-top: 1px solid #eee;
}
</style>
</head>
<body>
	<h1>我的购物车</h1>
	<%-- <img alt="" src="/image/go.jpg" style="cursor: pointer;" onclick="location.href='/list_product.jsp'"> --%>
	<h3>
		<a href="<%=basePath %>list_product.jsp">继续购物</a>
		<a href="<%=basePath %>clearCart">清空购物车</a>
		<a href="<%=basePath %>add_order.jsp">添加订单</a>

	</h3>
	<c:if test="${empty cart}">
		<h2>您没有添加商品</h2>
	</c:if>
	<c:if test="${not empty cart}">
		<table class="line" width="90%">
			<tr>
				<th>编号</th>
				<th>名称</th>
				<th>单价</th>
				<th>购买数量</th>
				<th>单项总价</th>
				<th>操作</th>
			</tr>
			<c:set var="total" value="0" scope="page"></c:set>
			<c:forEach var="entry" items="${cart}">
				<tr>
					<td class="line">${entry.key.id }</td>
					<td class="line">${entry.key.name }</td>
					<td class="line">${entry.key.price }</td>
					<td class="line"><input size="1" type="button" value="-"
						onclick="location.href='<%=basePath %>updateCart?id=${entry.key.id }&num=${entry.value-1 }'">
						<input type="text" value="${entry.value }" size="2"
						onblur="change(${entry.key.id })" id="shop${entry.key.id}">
						<input size="1" type="button" value="+"
						onclick="location.href='<%=basePath %>updateCart?id=${entry.key.id }&num=${entry.value+1 }'">
					</td>
					<td class="line">${entry.value * entry.key.price }</td>
					<c:set var="total" value="${entry.value * entry.key.price + total}"
						scope="page"></c:set>
					<td class="line"><a
						href="<%=basePath %>delCart?id=${entry.key.id }">删除</a></td>
				</tr>
			</c:forEach>
			<tr>
				<td colspan="5" align="right" class="line">合计金额：${total}</td>
			</tr>
		</table>
	</c:if>
</body>
</html>